import { ElMessage } from "element-plus";
import { reactive } from "vue";
// import { DEV, PROD } from "@/env";
const DEV = false;
export const baseFormList = [
  {
    label: "供应商名称",
    value: "company",
  },
  {
    label: "法人代表",
    value: "faren",
  },
  {
    label: "法人身份证",
    value: "idCard",
  },
  {
    label: "注册地区",
    value: "original",
  },
  {
    label: "企业邮箱",
    value: "email",
  },
  {
    label: "联系电话",
    value: "phone",
  },
  {
    label: "邮编",
    value: "postal",
  },
  {
    label: "传真",
    value: "cz",
  },
  {
    label: "注册资金/万元",
    value: "registerMon",
    type: "number",
  },
  {
    label: "营业执照",
    value: "certificate",
  },
  {
    label: "组织机构代码",
    value: "code",
  },
  {
    label: "经营许可证",
    value: "licence",
  },
  {
    label: "税务登记证代码",
    value: "tax",
  },
  {
    label: "银行",
    value: "bank",
  },
  {
    label: "银行账户",
    value: "account",
  },
];

export const textareaFormList = [
  {
    label: "煤源存放地点、数量、质量",
    value: "info",
    type: "textarea",
  },
  {
    label: "运输方式及保障能力",
    value: "transport",
    type: "textarea",
  },
  {
    label: "供应商介绍",
    value: "introduction",
    type: "textarea",
  },
];

export const certificateMessageFormList = reactive([
  {
    label: "营业执照",
    attr: "certificate",
    disabled: true,
    action: DEV ? "/api/upload/1.json" : "/api/upload/1",
    name: "multipartFile",
    drag: true,
    value: "",
    onSuccess(response) {
      response = response.response;
      if (!response) {
        return;
      }
      const {
        code,
        msg,
        data: { fileName },
      } = response;
      if (code === 200) {
        ElMessage({
          message: "上传成功",
          type: "success",
        });
        certificateMessageFormList[0].value = fileName;
      } else {
        ElMessage({
          message: msg,
          type: "warning",
        });
      }
    },
  },
  {
    label: "税务登记证",
    attr: "tax",
    disabled: true,
    action: DEV ? "/api/upload/2.json" : "/api/upload/2",
    name: "multipartFile",
    drag: true,
    value: "",
    onSuccess(response) {
      response = response.response;
      if (!response) {
        return;
      }
      const {
        code,
        msg,
        data: { fileName },
      } = response;
      if (code === 200) {
        ElMessage({
          message: "上传成功",
          type: "success",
        });
        certificateMessageFormList[1].value = fileName;
      } else {
        ElMessage({
          message: msg,
          type: "warning",
        });
      }
    },
  },
  {
    label: "组织机构代码证",
    attr: "code",
    disabled: true,
    action: DEV ? "/api/upload/3.json" : "/api/upload/3",
    name: "multipartFile",
    drag: true,
    value: "",
    onSuccess(response) {
      response = response.response;
      if (!response) {
        return;
      }
      const {
        code,
        msg,
        data: { fileName },
      } = response;
      if (code === 200) {
        ElMessage({
          message: "上传成功",
          type: "success",
        });
        certificateMessageFormList[2].value = fileName;
      } else {
        ElMessage({
          message: msg,
          type: "warning",
        });
      }
    },
  },
  {
    label: "开户许可证",
    attr: "account",
    disabled: true,
    action: DEV ? "/api/upload/4.json" : "/api/upload/4",
    name: "multipartFile",
    drag: true,
    value: "",
    onSuccess(response) {
      response = response.response;
      if (!response) {
        return;
      }
      const {
        code,
        msg,
        data: { fileName },
      } = response;
      if (code === 200) {
        ElMessage({
          message: "上传成功",
          type: "success",
        });
        certificateMessageFormList[3].value = fileName;
      } else {
        ElMessage({
          message: msg,
          type: "warning",
        });
      }
    },
  },
  {
    label: "经营许可证",
    attr: "management",
    disabled: true,
    action: DEV ? "/api/upload/5.json" : "/api/upload/5",
    name: "multipartFile",
    drag: true,
    value: "",
    onSuccess(response) {
      response = response.response;
      if (!response) {
        return;
      }
      const {
        code,
        msg,
        data: { fileName },
      } = response;
      if (code === 200) {
        ElMessage({
          message: "上传成功",
          type: "success",
        });
        certificateMessageFormList[4].value = fileName;
      } else {
        ElMessage({
          message: msg,
          type: "warning",
        });
      }
    },
  },
  {
    label: "法人身份证",
    attr: "idCard",
    disabled: true,
    action: DEV ? "/api/upload/6.json" : "/api/upload/6",
    name: "multipartFile",
    drag: true,
    value: "",
    onSuccess(response) {
      response = response.response;
      if (!response) {
        return;
      }
      const {
        code,
        msg,
        data: { fileName },
      } = response;
      if (code === 200) {
        ElMessage({
          message: "上传成功",
          type: "success",
        });
        certificateMessageFormList[5].value = fileName;
      } else {
        ElMessage({
          message: msg,
          type: "warning",
        });
      }
    },
  },
]);

export const baseForm = reactive({
  company: "",
  faren: "",
  idCard: "",
  original: "",
  email: "",
  postal: "",
  cz: "",
  phone: "",
  registerMon: 0,
  certificate: "",
  code: "",
  licence: "",
  tax: "",
  bank: "",
  account: "",
  info: "",
  transport: "",
  introduction: "",
});
